﻿using System.Linq;
using SweetSurvey.Models.Repositories;

namespace SweetSurvey.Models.ViewModels
{
    public class AnswerViewModel: IApplyChanges<Answer>
    {
        public string QuestionId { get; set; }
        public int SelectedIndex { get; set; }
        public IOptionRepository OptionRepository { get; set; }

        #region IApplyChanges<Answer> Members

        public void Apply(ref Answer model)
        {
            var option = this.OptionRepository.GetOptionsByQuestionId(this.QuestionId).Skip(SelectedIndex).First();
            model.OptionId = option.Id;
        }

        #endregion
    }
}